package com.asd.common.util;


/**
 * 
 * 转换风向方位
 * @author hong
 *
 */
public class WindConvertUtils {
	
	private static final String[] directArr = new String[] { "北", "东北偏北", "东北", "东北偏东", "东", "东南偏东", "东南", "东南偏南", "南",
            "西南偏南", "西南", "西南偏西", "西", "西北偏西", "西北", "西北偏北" };
	
	private static final String[] directCodeArr = new String[] { "N", "NNE", "NE", "ENE", "E", "ESE", "SE", "SSE", "S",
            "SSW", "SW", "WSW", "W", "WNW", "NW", "NNW" };
	
    /**
     * 
    N    北    0°
    NNE    东北偏北    22.5°
    NE    东北    45°
    ENE    东北偏东    67.5°
    E    东    90°
    ESE    东南偏东    112.5°
    SE    东南    135°
    SSE    东南偏南    157.5°
    S    南    180°
    SSW    西南偏南    202.5°
    SW    西南    225°
    WSW    西南偏西    247.5°
    W    西    270°
    WNW    西北偏西    292.5°
    NW    西北    315°
    NNW    西北偏北    337.5°
     */
    public static String windDirectionSwitch(String degrees_str) {
    	float degrees = 0;
    	try {
    		degrees = Float.parseFloat(degrees_str);
		} catch (Exception e) {
//			System.out.println(e.getMessage());
			return degrees_str;
		}
        int index = 0;
        if (348.75 <= degrees && degrees <= 360) {
            index = 0;
        } else if (0 <= degrees && degrees <= 11.25) {
            index = 0;
        } else if (11.25 < degrees && degrees <= 33.75) {
            index = 1;
        } else if (33.75 < degrees && degrees <= 56.25) {
            index = 2;
        } else if (56.25 < degrees && degrees <= 78.75) {
            index = 3;
        } else if (78.75 < degrees && degrees <= 101.25) {
            index = 4;
        } else if (101.25 < degrees && degrees <= 123.75) {
            index = 5;
        } else if (123.75 < degrees && degrees <= 146.25) {
            index = 6;
        } else if (146.25 < degrees && degrees <= 168.75) {
            index = 7;
        } else if (168.75 < degrees && degrees <= 191.25) {
            index = 8;
        } else if (191.25 < degrees && degrees <= 213.75) {
            index = 9;
        } else if (213.75 < degrees && degrees <= 236.25) {
            index = 10;
        } else if (236.25 < degrees && degrees <= 258.75) {
            index = 11;
        } else if (258.75 < degrees && degrees <= 281.25) {
            index = 12;
        } else if (281.25 < degrees && degrees <= 303.75) {
            index = 13;
        } else if (303.75 < degrees && degrees <= 326.25) {
            index = 14;
        } else if (326.25 < degrees && degrees <= 360.0) {
            index = 15;
        } else {
            return degrees_str;
        }
        return directArr[index];
    }
    
    public static String windDirectionCodeSwitch(String degrees_str) {
    	float degrees = 0;
    	try {
    		degrees = Float.parseFloat(degrees_str);
		} catch (Exception e) {
//			System.out.println(e.getMessage());
			return degrees_str;
		}
        int index = 0;
        if (348.75 <= degrees && degrees <= 360) {
            index = 0;
        } else if (0 <= degrees && degrees <= 11.25) {
            index = 0;
        } else if (11.25 < degrees && degrees <= 33.75) {
            index = 1;
        } else if (33.75 < degrees && degrees <= 56.25) {
            index = 2;
        } else if (56.25 < degrees && degrees <= 78.75) {
            index = 3;
        } else if (78.75 < degrees && degrees <= 101.25) {
            index = 4;
        } else if (101.25 < degrees && degrees <= 123.75) {
            index = 5;
        } else if (123.75 < degrees && degrees <= 146.25) {
            index = 6;
        } else if (146.25 < degrees && degrees <= 168.75) {
            index = 7;
        } else if (168.75 < degrees && degrees <= 191.25) {
            index = 8;
        } else if (191.25 < degrees && degrees <= 213.75) {
            index = 9;
        } else if (213.75 < degrees && degrees <= 236.25) {
            index = 10;
        } else if (236.25 < degrees && degrees <= 258.75) {
            index = 11;
        } else if (258.75 < degrees && degrees <= 281.25) {
            index = 12;
        } else if (281.25 < degrees && degrees <= 303.75) {
            index = 13;
        } else if (303.75 < degrees && degrees <= 326.25) {
            index = 14;
        } else if (326.25 < degrees && degrees <= 360.0) {
            index = 15;
        } else {
            return degrees_str;
        }
        return directCodeArr[index];
    }

}
